package com.tsky.yyj.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.tsky.casing.QueryBean;
import com.tsky.casing.action.BackAction;
import com.tsky.common.ActionUtil;
import com.tsky.common.BeanUtil;
import com.tsky.yyj.entity.Product;
import com.tsky.yyj.json.YYJJsonFormat;
import com.tsky.yyj.manager.BaseManager;

@Component("productAction")
@Scope("prototype")
public class ProductAction extends BackAction {
	@Autowired
	private BaseManager entityManager;

	/* bean properties */
	private String ids;
	private String id;// 序号
	private String code;// 用户名
	private String name;// 姓名
	private String idCode;// 身份证
	private String phone;// 手机号
	private String payCode;// 支付宝账号
	private String bankCode;// 银行账号
	private String email;// 邮件地址

	public void grid() {
		QueryBean grid = new QueryBean();
		BeanUtil.copyProperties(grid, this);

		entityManager.query(grid, Product.class);

		String jsonData = YYJJsonFormat.productToJson(grid);
		ActionUtil.ajaxWrite(jsonData);
	}

	public void add() {
		Product entity = new Product();
		BeanUtil.copyProperties(entity, this);
		entity.setId(BeanUtil.getID());

		boolean result = entityManager.saveEntity(entity);
		ActionUtil.ajaxWrite(result);
	}

	public void delete() {
		String[] idset = ids.split(",");
		boolean result = entityManager.delEntity(Product.class, idset);
		ActionUtil.ajaxWrite(result);
	}

	public String query() {
		Product entity = entityManager.getEntity(Product.class, id);
		ActionUtil.setToEL("productEnt", entity);
		return "query";
	}

	public void update() {
		Product entity = entityManager.getEntity(Product.class, id);
		BeanUtil.copyProperties(entity, this);

		boolean result = entityManager.updateEntity(entity);
		ActionUtil.ajaxWrite(result);
	}

	public BaseManager getEntityManager() {
		return entityManager;
	}

	public void setEntityManager(BaseManager entityManager) {
		this.entityManager = entityManager;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getIdCode() {
		return idCode;
	}

	public void setIdCode(String idCode) {
		this.idCode = idCode;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getPayCode() {
		return payCode;
	}

	public void setPayCode(String payCode) {
		this.payCode = payCode;
	}

	public String getBankCode() {
		return bankCode;
	}

	public void setBankCode(String bankCode) {
		this.bankCode = bankCode;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

}
